<link href="css/style.css" rel="stylesheet" type="text/css" />
<?php 
					$daction = $_SESSION['action'];
		session_start();
		$lang = $_SESSION['lang'];
		//Get information of document
		
		$query = mysql_query("select a.Tile,a.Content,a.Timecreate,a.TripDate,a.purpose,a.Content2,a.Description,a.comment,
				e.Fullname,a.IDGroupApprove,a.IDStatus,a.IDEmployee
				from approvedoc a inner join employee e on a.IDEmployee = e.IDEmployee 
				where a.IDApproveDoc = '$id'");
		while ($row = mysql_fetch_array($query))
		{
			$dcomment = $row[comment];
			$dtitle = $row[Tile];
			$ddescription = $row[Description];
			$dtime = $row[Timecreate];
			$duser = $row[Fullname];
			$demployeeperforment = $row[EmployeePerforment];
			$dtripdate = $row[TripDate];
			$dlocation = $row[Location];
			$dtotaltime = $row[TotalTime];
			$didgroupapprover = $row[IDGroupApprove];
			$dcontent = $row[Content];
			$dcontent2 = $row[Content2];
			$dpurpose = $row[purpose];
			$didemployee = $row[IDEmployee];
			$dstatus = $row[IDStatus];
		}
		$flagmysending=false;
		if($daction == "my_sending"){
			$result=mysql_query("select listapprove.ID FROM listapprove WHERE IDGroupApprove='".$didgroupapprover."' and (IDStatus = 1 or IDStatus = 3 or IDStatus > 9)");
			if(mysql_num_rows($result)==0){
				$flagmysending=true;
			}
		}
		
		$queryEmployee = mysql_query("SELECT e.FullName,dl.DepartmentName,e.Position
				FROM employee e INNER JOIN department_lang dl ON dl.IDDepartment = e.IDDepartment
				WHERE e.IDEmployee = '$didemployee' AND dl.LangID = '$lang'");
		while ($row = mysql_fetch_array($queryEmployee))
		{
			$dnameemployee = $row[FullName];
			$dnamedepartment = $row[DepartmentName];
			$dposition = $row[Position];
		}
		
		$query1 = mysql_query("SELECT l.IDStatus,l.DateApprove,e.Fullname,l.Description,l.IDEmployee FROM listapprove l
                    						INNER JOIN employee e ON l.IDEmployee = e.IDEmployee
                    						WHERE CONVERT(l.IDGroupApprove USING utf8) = CONVERT('$didgroupapprover' USING utf8)
                    						ORDER BY l.Order ASC");
		if($daction=="re_not_approve"){
		$lang = $_SESSION['lang'];
		$queryDepartment = mysql_query("SELECT d.IDDepartment,dl.DepartmentName FROM department d,department_lang dl WHERE d.IDDepartment=dl.IDDepartment AND dl.LangID='$lang';");
		$queryReference = mysql_query("SELECT e.IDEmployee,e.FullName FROM list_reference lr,employee e WHERE e.IDEmployee=lr.id_employee AND lr.id_group='$didgroupapprover' AND lr.id_manager='$id_employee' AND lr.id_status !=1;");
		
			
			include 'popup/popup_reference.php';
		}
	?>
<style>.print{font-size:18px !important;margin:auto !important;width:90% !important;}
			.print table {border-collapse:collapse !important;width:90% !important;}
			.print td{border: 1px solid #999 !important;padding: 5px !important}
			
			.print td .first{
				background: #E8E8E8 !important; 
				padding:5px !important; 	
				font-weight:bold !important;; 
			}
			
</style>
<script>
			
			function printStart(){
				document.getElementById("header").style.display = "none";
				document.getElementById("menuleft").style.display = "none";
				document.getElementById("menu").style.display = "none";
				document.getElementById("footer").style.display = "none";
				document.getElementById("list").className="print";
				window.print();
				if(/Chrome/.test(navigator.userAgent)){
					  $(window).focus(function(){
						  location.reload(true);
					  });
					} else {
						  location.reload(true);
				}
				
			}
		
		</script>
<div class="title"></div>
<form action="approve-handle.php" method="get">
<input type="hidden" name="id" value="<?=$id?>" />
<input type="hidden" name="type" value="<?=$type?>" />
<div class="main_content" style="min-height: 895px;background-color: white">
	<div id="menu">
            <ul class="top_but">
				
	<?php if($daction=="re_not_approve"  || $daction=="my_saved"){?>
				<li><?php if(isset($_REQUEST['page'])){?>
						<a href="<?=$_SERVER['HTTP_REFERER']?>&page=<?=$_REQUEST['page']?>"><img src="images/back.png" alt="" /></a>
					<?php }else{?>
						<a href="<?=$_SERVER['HTTP_REFERER']?>"><img src="images/back.png" alt="" /></a>
					<?php }?><p class="hidden"><?=$l_back?></p></li>
	<?php }else{?>
				<li><?php if(isset($_REQUEST['page'])){?>
						<a href="<?=$_SERVER['HTTP_REFERER']?>&page=<?=$_REQUEST['page']?>"><img src="images/back.png" alt="" /></a>
					<?php }else{?>
						<a href="<?=$_SERVER['HTTP_REFERER']?>"><img src="images/back.png" alt="" /></a>
					<?php }?><p class="hidden"><?=$l_back?></p></li>
				<li><a href="printer/printer13.php?id=<?=$id?>&type=<?=$type?>" target="_blank"><img src="images/print.png" alt="" /></a><p class="hidden"><?=$l_print?></p></li>
	<?php }?>
	<?php if($daction=="mybin_senddoc"){
			$_SESSION['idGroup']=$didgroupapprover;
			$_SESSION['id_employee']=$id_employee;
	?>
				<li><input type="submit" name="Restore" value="" style="background:url(images/restore.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden"><?=$l_restore?></p></li>
	<?php }?>
	<?php if($daction=="re_not_approve"){
			$_SESSION['idGroup']=$didgroupapprover;
			$_SESSION['id_employee']=$id_employee;
	?>
				
				
				<li><input type="submit" name="Approve" value="" style="background:url(images/ok.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden"><?=$l_approve?></p></li>
				<li><input type="submit" name="Reject" value="" style="background:url(images/deny.png) no-repeat; width:36px; height:36px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden"><?=$l_reject?></p></li>
				<li><input type="button" onclick="popup_window_show('#sample', { pos : 'window-center', width : '600px', height:'800px'});" value="" name="Reference" style="background:url(images/refer.png) no-repeat; width:36px; height:36px; border:none; position:absolute; top:0; left:0; right:0; bottom:0; margin:auto" /><p class="hidden"><?=$l_reference?></p></li>
	<?php }?>
	<?php
		 if($daction == "re_reference_waiting"){
			$_SESSION['idGroup']=$didgroupapprover;
			$_SESSION['id_employee']=$id_employee;
	?>
				<li><input type="submit" name="Accept" value="" style="background:url(images/ok.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden"><?=$l_accept?></p></li>
	<?php }?>
	<?php
		 if($daction == "my_declined" || $flagmysending==true){
			$_SESSION['idGroup']=$didgroupapprover;
			$_SESSION['id_employee']=$id_employee;
	?>
				<li><input type="submit" name="Edit" value="" style="background:url(images/edit.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden">Edit</p></li>
				<li><input type="submit" name="Delete" value="" style="background:url(images/trash.png) no-repeat; width:32px; height:32px; border:none; position:absolute; top:0px; left:0px; right:0px; bottom:0px; margin:auto" /><p class="hidden">Delete</p></li>
	<?php }?>
			</ul>
		</div>
		<div id="list">
            <table class="tcontent" cellpadding="5" cellspacing="0">
            	<?php 
               		if( $daction == "re_not_approve"){
               ?> 	
              <tr>
                <td class="col_left" width="15%"><?=$l_comment?></td>
                <td colspan="3" style="padding: 1px 1px"><textarea name="textarea" cols="5" rows="3" style="width:99%; border:1px solid #c4c0c9"></textarea></td>
              </tr>
              <?php } ?>
              <tr>
                <td class="col_left" width="15%"><?=$l_approver?></td>
                <td colspan="3" style="padding: 1px 1px">
                    	<table class="tcontent" cellpadding="5" cellspacing="0">
                        	
                    				<?
                    				//Get group approver
                    				
                    				
                    				$i=1;
                    				while ($row = mysql_fetch_array($query1))
                    				{
                    					$dnameapprover = $row[Fullname];
                    					$ddateapproved = $row[DateApprove];
                    					$dcommentm=$row[Description];
                    					$didEmployee=$row[IDEmployee];
                    					if ($row[IDStatus] == 1){
	                    					$dstatus=$l_status_complete;
	                    				} else if ($row[IDStatus] == 2){
	                    					$dstatus=$l_status_pending;
	                    				}else if ($row[IDStatus] == 3){
	                    					$dstatus=$l_status_declined;
	                    				}else if ($row[IDStatus] == 4){
	                    					$dstatus=$l_status_saved;
	                    				}else if ($row[IDStatus] == 5){
	                    					$l_status_reference;
	                    				}
                    				?>
                    				
                    				<tr>	
                    					<td rowspan="2"  style="padding: 5px 5px;color:blue;width: 100px"><?=$l_step?> <?=$i?> </td>
                    					<td  style="padding: 5px 5px; width: 500px" >
		                    				<span style="display: block;">
		                    					<b><?=$dnameapprover?></b>_<?=$dstatus?> <?=$ddateapproved?>
		                    				</span>
	                    				</td>
	                    				<td style="padding: 5px 5px"> <div align="left"><?=$l_reference?> :
		                                	<?
		                    				//Get list references
		                    				$query2 = mysql_query("SELECT e.Fullname FROM list_reference l
		                    						INNER JOIN employee e ON l.id_employee = e.IDEmployee
		                    						WHERE CONVERT(l.id_group USING utf8) = CONVERT('$didgroupapprover' USING utf8) AND
		                    									l.id_manager='$didEmployee'") ;
		                    				
		                    				while ($row1 = mysql_fetch_array($query2))
		                    				{
		                    					$dnamereferences = $row1[Fullname];
		                    				?>
		                    				<b><?=$dnamereferences?></b>;
		                    				<?
		                    				}
		                    				?>
		                                
		                               </div> </td>
                    				</tr>
                    				<?php if($ddateapproved ==null){?>
                    				<tr >
                    				</tr>
                    				<?php }else{?>	
                    				<tr >
                    					<td colspan="2" style="padding: 5px 5px"><div align="left"><b><?=$l_comment?> : </b><?=$dcommentm?> </div></td>
                    				</tr>
                    				<?php }?>
                    				
                    				<?
                    					$i++;
                    				}
                    				?>
                    				
                        </table>                    </td>
              </tr>
              <tr>
                <td class="col_left"><?=$l_department?>/<?=$l_employee?></td>
                <td colspan="3"><div align="left"><?=$dnameemployee?> (<?=$dnamedepartment?>)</div></td>
              </tr>
              <tr>
                <td class="col_left" width="15%"><?=$l_title?></td>
                <td colspan="3"><div align="left"><?=$dtitle?></div></td>
              </tr>
              <tr>
                <td class="col_left" width="15%"><?=$l_content?></td>
                <td colspan="3"><div align="left"><?=$dcontent?></div></td>
              </tr>
              <tr>
                	<td class="col_left" width="15%"><?=$l_created_date?></td>
                  	<td><div align="left"><?=$dtime?></div></td>
                    <td class="col_left" width="15%"><?=$l_purchase_date?></td>
                    <td><div align="left"><?=$dtripdate?></div></td>       
                </tr>  
                <tr>
                <td class="col_left" width="15%"><?=$l_purpose?></td>
                <td colspan="3"><div align="left"><?=$dpurpose?></div></td>
              </tr>
              <tr>
                <td class="col_left" width="15%"><?=$l_project?></td>
                <td colspan="3"><div align="left"><?=$dcontent2?></div></td>
              </tr>
              <tr>
                <td class="col_left" width="15%"><?=$l_description?></td>
                <td colspan="3"><div align="left"><?=$ddescription?></div></td>
              </tr>
              <tr>
                <td colspan="4" style="padding: 0px 0px; "><table width="100%" class="tcontent" cellpadding="5" cellspacing="0">
                	<tr class="col_left" style="border-bottom: 1px solid #ccc;">
                		<th width="3%"><?=$l_no?></th>
						<th width="23%"><?=$l_product_item?></th>
						<th width="23%"><?=$l_company_name?></th>
						<th width="7%"><?=$l_quantity?></th>
						<th width="8%"><?=$l_price?></th>
						<th width="8%"><?=$l_price_vat?></th>
						<th width="8%"><?=$l_total_amount?></th>
					</tr>
                    
                  <?
					$querybuy = mysql_query("select * from buying_document where document_id = '$id'");
					$dtotalamountt = 0;
					$i=1;
					while ($row = mysql_fetch_array($querybuy))
					{
						$dproductitem = $row[name];
						$dcompanyname = $row[company];
						$dquantity = $row[amount];
						$dprice = $row[price];
						$dpricevat = $row[vat];
						$dtotalamount = $row[total];
						$dtotalamountt = $dtotalamount + $dtotalamountt;
					?>
					<tr>
						<td><?=$i?></td>
						<td><?=$dproductitem?></td>
						<td><?=$dcompanyname?></td>
						<td><?=$dquantity?></td>
						<td><?=number_format($dprice)?></td>
						<td><?=number_format($dpricevat)?></td>
						<td style="text-align:right;padding-right:4px;"><?=number_format($dtotalamount)?></td>
					</tr>
					<?
					$i++;
					}
					?>                  
                </table></td>
              </tr>
              <tr>
                <td class="col_left" width="15%"><?=$l_total_amount?></td>
                <td colspan="3"><div align="right"><?=number_format($dtotalamountt)?></div></td>
              </tr>
              <tr>
                <td class="col_left" width="15%"><?=$l_comment ?></td>
                <td colspan="3"><div align="left"><?=$dcomment?></div></td>
              </tr>             
          </table>
          </div>
      </div>
</form>